package com.ourteam.workspace.dao.impl;

import com.ourteam.workspace.dao.IWorkspaceConfigDAO;
import com.ourteam.workspace.dao.WorkspaceConfig;
import com.ourteam.workspace.dao.WorkspaceConfigDAOQueryBean;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import net.dao.AbstractSpringDAO;
import net.dao.DataAccessObjectHelper;
import org.apache.commons.beanutils.PropertyUtils;
import org.springframework.jdbc.core.RowMapper;

/**
 * Template Name : DAO服务对象 Template Version : 1 Template Last Modfiy Date : Fri Nov 17 11:00:11 CST
 * 2017 Auto Generate Date : 2018-11-30 18:42:33 Warning ! This file will be overwrite when
 * regenerate !
 */
public class AbstractWorkspaceConfigDAOJdbcImpl extends AbstractSpringDAO
    implements IWorkspaceConfigDAO {

  public static final String[] ENTITY_FIELDS =
      new String[] {Id, ConfigItem, Description, ParentConfigId, Status, ConfigForm, ConfigName};

  public static final String[] ENTITY_PROPERTIES =
      new String[] {
        _DataObjectProperty.Id,
        _DataObjectProperty.ConfigItem,
        _DataObjectProperty.Description,
        _DataObjectProperty.ParentConfigId,
        _DataObjectProperty.Status,
        _DataObjectProperty.ConfigForm,
        _DataObjectProperty.ConfigName
      };

  public static final String[] ENTITY_PK_FIELDS = new String[] {Id};

  public static final String[] ENTITY_AUTO_GEN_PK_FIELDS = new String[] {Id};

  public static final String[] ENTITY_UNIQUE_FIELDS = new String[] {};

  private static String relatedJoinSQL = null;

  private static String basicFilterSQL = null;

  private DataAccessObjectHelper<WorkspaceConfig, WorkspaceConfigDAOQueryBean> daoHelper;

  public AbstractWorkspaceConfigDAOJdbcImpl() {
    super();
    daoHelper = new DataAccessObjectHelper<WorkspaceConfig, WorkspaceConfigDAOQueryBean>(this);
  }

  protected String getEntityName() {
    return EntityName;
  }

  protected String[] getEntityFields() {
    return ENTITY_FIELDS;
  }

  protected String[] getEntityProperties() {
    return ENTITY_PROPERTIES;
  }

  protected String[] getEntityPKFields() {
    return ENTITY_PK_FIELDS;
  }

  protected String[] getEntityAutoGenPKFields() {
    return ENTITY_AUTO_GEN_PK_FIELDS;
  }

  protected String[] getEntityUniqueFields() {
    return ENTITY_UNIQUE_FIELDS;
  }

  protected String getBaiscQueryFilter() {

    if (basicFilterSQL == null) {
      StringBuffer basicFilterSQLbuffer = new StringBuffer();

      basicFilterSQL = basicFilterSQLbuffer.toString();
    }

    return basicFilterSQL;
  }

  protected String getRelatedJoinSQL() {

    if (relatedJoinSQL == null) {
      StringBuffer relatedJoinSQLBuffer = new StringBuffer();

      relatedJoinSQL = relatedJoinSQLBuffer.toString();
    }

    return relatedJoinSQL;
  }

  /**
   * Check Data Unique
   *
   * @param aWorkspaceConfig
   * @throws Exception
   */
  public boolean checkIsUnique(WorkspaceConfig aWorkspaceConfig) throws Exception {

    if (aWorkspaceConfig == null) {
      return true;
    }

    List valueList = new ArrayList();

    List pkValueList = new ArrayList();

    pkValueList.add(aWorkspaceConfig.getId());

    return isUnique(
        valueList.toArray(new Object[valueList.size()]),
        pkValueList.toArray(new Object[pkValueList.size()]));
  }

  /**
   * Insert Data
   *
   * @param aWorkspaceConfig
   * @throws Exception
   */
  public void insert(WorkspaceConfig aWorkspaceConfig) throws Exception {

    super.doInsert(aWorkspaceConfig);
  }

  /**
   * Batch Insert Datas
   *
   * @param aWorkspaceConfig
   * @throws Exception
   */
  public void batchInsert(WorkspaceConfig[] aWorkspaceConfigs) throws Exception {

    super.doBatchInsert(aWorkspaceConfigs);
  }

  /**
   * Delete Data
   *
   * @param final long id *
   * @throws Exception
   */
  public void delete(final long id) throws Exception {

    super.doDeleteById(new Object[] {new Long(id)});
  }

  /**
   * Delete Datas
   *
   * @param queryBean
   * @throws Exception
   */
  public void delete(WorkspaceConfigDAOQueryBean queryBean) throws Exception {

    super.doDeleteByQuery(queryBean);
  }

  public void delete(WorkspaceConfig aWorkspaceConfig) throws Exception {

    delete(aWorkspaceConfig.getId());
  }

  /**
   * Update Data Selective
   *
   * @param aWorkspaceConfig
   * @throws Exception
   */
  public void update(WorkspaceConfig aWorkspaceConfig) throws Exception {

    if (aWorkspaceConfig.getId() == 0) {
      throw new Exception("Can not update object data whith out primary key value");
    }

    super.doUpdate(aWorkspaceConfig);

    WorkspaceConfig tempObj = findById(aWorkspaceConfig.getId());

    if (tempObj != null) {
      PropertyUtils.copyProperties(aWorkspaceConfig, tempObj);
    }
  }

  /**
   * Batch Update Datas
   *
   * @param aWorkspaceConfigs[]
   * @throws Exception
   */
  public void batchUpdate(WorkspaceConfig[] aWorkspaceConfigs) throws Exception {

    super.doBatchUpdate(aWorkspaceConfigs);
  }

  /**
   * Update Data By Condictions
   *
   * @param aWorkspaceConfig
   * @param aValueCriteria
   * @param aTransaction
   * @throws Exception
   */
  public void update(WorkspaceConfig aWorkspaceConfig, WorkspaceConfigDAOQueryBean aQueryBean)
      throws Exception {

    super.doUpdateByQuery(aWorkspaceConfig, aQueryBean);
  }

  /**
   * Update Data By Condictions
   *
   * @param aQueryBean
   * @throws Exception
   */
  public void update(WorkspaceConfigDAOQueryBean aQueryBean) throws Exception {
    super.doUpdateByQuery(aQueryBean);
  }

  protected void checkNullValue(WorkspaceConfig aWorkspaceConfig) throws Exception {

    if (aWorkspaceConfig.getConfigItem() == null) {
      throw new Exception("The WorkspaceConfig.configItem value is not allow NULL");
    }

    if (aWorkspaceConfig.getDescription() == null) {
      throw new Exception("The WorkspaceConfig.description value is not allow NULL");
    }

    if (aWorkspaceConfig.getStatus() == null) {
      throw new Exception("The WorkspaceConfig.status value is not allow NULL");
    }
  }

  /**
   * Get Data By ID
   *
   * @param final long id * @return ${businessObject.name}
   * @throws Exception
   */
  public WorkspaceConfig findById(final long id) throws Exception {

    WorkspaceConfigDAOQueryBean queryBean = new WorkspaceConfigDAOQueryBean();

    WorkspaceConfigDAOQueryBean.Criteria criteria = queryBean.createCriteria();

    criteria.andIdEqualTo(id);

    // queryBean.setDistinct(true);

    WorkspaceConfig[] WorkspaceConfigs = query(queryBean);

    if (WorkspaceConfigs.length == 0) {
      return null;
    } else {
      return WorkspaceConfigs[0];
    }
  }

  /**
   * Query Data
   *
   * @param queryBean
   * @return WorkspaceConfig[]
   * @throws Exception
   */
  public WorkspaceConfig[] query(WorkspaceConfigDAOQueryBean queryBean) throws Exception {

    List result = super.doQuery(queryBean, new JdbcWorkspaceConfigRowMapper());

    return (WorkspaceConfig[]) result.toArray(new WorkspaceConfig[result.size()]);
  }

  /**
   * Query ${businessObject.name} Selective
   *
   * @param queryBean
   * @return Map[]
   * @model
   * @throws Exception
   */
  public Map<String, Object>[] querySelective(WorkspaceConfigDAOQueryBean queryBean)
      throws Exception {

    if (queryBean.getSelectProperties().isEmpty()) {
      queryBean.addAllSelectProperties();
    }

    return super.doQuerySelective(queryBean);
  }

  /**
   * Query Data Count
   *
   * @param queryBean
   * @return int
   * @throws Exception
   */
  public int queryCount(WorkspaceConfigDAOQueryBean queryBean) throws Exception {

    return super.doQueryCount(queryBean);
  }

  public void synchronize(
      WorkspaceConfig[] aWorkspaceConfigs, WorkspaceConfigDAOQueryBean queryBean) throws Exception {
    daoHelper.synchronize(aWorkspaceConfigs, queryBean);
  }

  public void synchronize(
      WorkspaceConfig[] aWorkspaceConfigs,
      WorkspaceConfigDAOQueryBean queryBean,
      net.dao.IDataAccessInterface.ISynchronizeCallback<WorkspaceConfig> callBack)
      throws Exception {
    daoHelper.synchronize(aWorkspaceConfigs, queryBean, callBack);
  }

  public static class JdbcWorkspaceConfigRowMapper implements RowMapper<WorkspaceConfig> {

    public WorkspaceConfig mapRow(ResultSet resultSet, int arg1) throws SQLException {
      WorkspaceConfig object = new WorkspaceConfig();

      int columnIndex = 1;

      int __dataType;

      try {

        Object id = null;

        id = resultSet.getObject(columnIndex++);

        object.setIdNull(resultSet.getBoolean(columnIndex++));

        if (id != null) {

          setBeanValue(object, _DataObjectProperty.Id, id);
        }

        Object configItem = null;

        configItem = resultSet.getObject(columnIndex++);

        object.setConfigItemNull(resultSet.getBoolean(columnIndex++));

        if (configItem != null) {

          setBeanValue(object, _DataObjectProperty.ConfigItem, configItem);
        }

        Object description = null;

        description = resultSet.getObject(columnIndex++);

        object.setDescriptionNull(resultSet.getBoolean(columnIndex++));

        if (description != null) {

          setBeanValue(object, _DataObjectProperty.Description, description);
        }

        Object parentConfigId = null;

        parentConfigId = resultSet.getObject(columnIndex++);

        object.setParentConfigIdNull(resultSet.getBoolean(columnIndex++));

        if (parentConfigId != null) {

          setBeanValue(object, _DataObjectProperty.ParentConfigId, parentConfigId);
        }

        Object status = null;

        status = resultSet.getObject(columnIndex++);

        object.setStatusNull(resultSet.getBoolean(columnIndex++));

        if (status != null) {

          setBeanValue(object, _DataObjectProperty.Status, status);
        }

        Object configForm = null;

        configForm = resultSet.getObject(columnIndex++);

        object.setConfigFormNull(resultSet.getBoolean(columnIndex++));

        if (configForm != null) {

          setBeanValue(object, _DataObjectProperty.ConfigForm, configForm);
        }

        Object configName = null;

        configName = resultSet.getObject(columnIndex++);

        object.setConfigNameNull(resultSet.getBoolean(columnIndex++));

        if (configName != null) {

          setBeanValue(object, _DataObjectProperty.ConfigName, configName);
        }

        return object;
      } catch (Exception e) {
        throw new SQLException(e.getMessage());
      }
    }
  }
}
